Repository navigation
Conversation
mhalbritter
left a comment
There was a problem hiding this comment.
Hello,
thanks for the PR. I've left some comments for your consideration.
| When a `PUT` request is received to replace an existing entity: | ||
|
|
||
| 1. The existing entity is loaded from the repository. | ||
| 2. The request body is applied on top of the existing entity (non-null fields from the request body overwrite the existing entity's fields). |
There was a problem hiding this comment.
Please verify that claim. I think PUT replaces the whole entity.
| | Event | Triggered By | Object Passed to Handler | ||
|
|
||
| | `BeforeCreateEvent` | ||
| | `POST` on collection resource |
There was a problem hiding this comment.
What happens on a PUT on a non-existent resource?
| | New, unsaved domain object (deserialized from request body) | ||
|
|
||
| | `AfterCreateEvent` | ||
| | `POST` on collection resource |
There was a problem hiding this comment.
What happens on a PUT on a non-existent resource?
|
|
||
| Validators are invoked as part of the Spring Data REST event lifecycle. Understanding _when_ each validator fires and _what object_ it receives is essential for writing correct validation logic. | ||
|
|
||
| The following table shows the event prefix used for bean name wiring, the HTTP operation that triggers it, and the state of the object passed to the validator: |
There was a problem hiding this comment.
Please double check that bean name wiring still works. I don't think it does.
| [[validation.assigning-validators]] | ||
| == Assigning Validators by Bean Name | ||
|
|
||
| To use the bean name prefix approach, declare a `Validator` bean whose name starts with the event prefix followed by the domain type name. Spring Data REST automatically wires it to the correct event. |
There was a problem hiding this comment.
Please double check that this still works. I don't think it does.
There was a problem hiding this comment.
Fixed in previous commit
|
@mhalbritter, thanks very much for your review. I implemented your recommended changes in commit: 21b3907 |
|
Hello @ruthst00 , the 2nd commit you pushed is not signed off. Please sign it off. Thanks! |
…GitHub issue DATAREST-789 Signed-off-by: ruthes00 <ruthes00@gmail.com>
21b3907 to
8cbf92c
Compare
|
@mhalbritter, I squashed the two commits and made sure the sign-off message was preserved. Thanks! |
|
Thanks @ruthst00 , this is merged and backported. |
Fixes #1161
Solution
The documentation has been updated in two files to resolve GitHub issue DATAREST-789 (#1161):
src/main/antora/modules/ROOT/pages/events.adoc— Added a new "Event Lifecycle and Object State" section that:POST,PUT,PATCH,DELETE, and association resource operationsPATCHbehavior:BeforeSaveEventreceives the already-merged domain object (existing entity + patch applied), not the raw partial inputsrc/main/antora/modules/ROOT/pages/validation.adoc— Added a new "Validation Events and Object State" section that:beforeSave,beforeCreate) to its HTTP trigger and the object state the validator receivesbeforeSavevalidators receive the fully-merged entity for PATCH (not a partial object), with a concrete code example showing it is safe to validate all fieldsbeforeCreateandbeforeSavevalidators